#include "optionswidget.h"
#include "filetable.h"
#include "slepui.h"


void OptionsWidget::createTerminationOptions(){
    QLayout *layout = new QVBoxLayout(this);
    QWidget *terminationOptionsWidget = new QWidget(this);
    terminationOptionsWidget->setLayout(layout);

    tabWidget->addTab(terminationOptionsWidget,tr("Termination"));

    terminationOptions = new QGroupBox(tr("Termination Options"),this);
    QGridLayout *gterminationLayout = new QGridLayout;
    labelMaxIter = new QLabel(tr("Maximum Iterations"),this);
    spinBoxMaxIter = new QSpinBox(this);
    spinBoxMaxIter->setRange(1,1000000);
    spinBoxMaxIter->setSingleStep(10);
    spinBoxMaxIter->setValue(1000);
    labelMaxIter->setBuddy(spinBoxMaxIter);
    gterminationLayout->addWidget(labelMaxIter,0,0,Qt::AlignLeft);
    gterminationLayout->addWidget(spinBoxMaxIter,0,1,Qt::AlignCenter);

    opts->maxIter=1000;

    labelTolerance = new QLabel(tr("Tolerance"),this);
    dspinBoxTolerance = new QDoubleSpinBox(this);
    dspinBoxTolerance->setDecimals(6);
    dspinBoxTolerance->setRange(0.000001,1.0);
    dspinBoxTolerance->setSingleStep(0.00001);
    dspinBoxTolerance->setValue(0.0001);
    labelTolerance->setBuddy(dspinBoxTolerance);
    gterminationLayout->addWidget(labelTolerance,1,0,Qt::AlignLeft);
    gterminationLayout->addWidget(dspinBoxTolerance,1,1,Qt::AlignCenter);
    opts->tol = 0.0001;

    buttonGroupTFlag = new QButtonGroup(this);
    labelTFlag = new QLabel(tr("Termination condition:"),this);

    buttonGroupTFlag->addButton(new QRadioButton(tr("f - fprevious < tolerance")),0);
    buttonGroupTFlag->addButton(new QRadioButton(tr("f - fprevious < (tolerance * f)")),1);
    buttonGroupTFlag->addButton(new QRadioButton(tr("f < tolerance ")),2);
    buttonGroupTFlag->addButton(new QRadioButton(tr("|x-xprevious|_2 < tolerance ")),3); //euclidean distance between successive solutions
    buttonGroupTFlag->addButton(new QRadioButton(tr("|x-xprevious|_2 < tolerance * |x|_2")),4);
    buttonGroupTFlag->addButton(new QRadioButton(tr("Run for maximum iterations")),5);
    buttonGroupTFlag->setExclusive(true);

    (buttonGroupTFlag->button(5))->setChecked(true);
    opts->tFlag=5;

    labelTFlag->setBuddy(buttonGroupTFlag->button(0));

    gterminationLayout->addWidget(labelTFlag,2,0,6,1, Qt::AlignTop | Qt::AlignLeft);
    gterminationLayout->addWidget(buttonGroupTFlag->button(0),2,1,Qt::AlignLeft);
    gterminationLayout->addWidget(buttonGroupTFlag->button(1),3,1,Qt::AlignLeft);
    gterminationLayout->addWidget(buttonGroupTFlag->button(2),4,1,Qt::AlignLeft);
    gterminationLayout->addWidget(buttonGroupTFlag->button(3),5,1,Qt::AlignLeft);
    gterminationLayout->addWidget(buttonGroupTFlag->button(4),6,1,Qt::AlignLeft);
    gterminationLayout->addWidget(buttonGroupTFlag->button(5),7,1,Qt::AlignLeft);

    terminationOptions->setLayout(gterminationLayout);
    layout->addWidget(terminationOptions);
    ((QBoxLayout*)layout)->addStretch();
}